package com.yyks.es.dubbo.pojo.vo.search;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yyks.es.dubbo.pojo.model.EsHotelInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class HotelInfoHotelUnionSearchVoHotle extends EsHotelInfo {

    @ApiModelProperty("距离")
    private Integer distance;
    //房间id列表
    @JsonIgnore
    private String roomIds;
    @ApiModelProperty("房间信息")
    List<HotelInfoHotelUnionSearchVoRoom> rooms;
    //图片
    private List<String> images;
    private String star;
    private Integer minPrice;
    @ApiModelProperty("设施列表")
    private List<String> installation;

    @JsonIgnore
    public List<Integer> getRoomIds() {
        ArrayList<Integer> roomIdsList = new ArrayList<>();
        if (StrUtil.isNotBlank(roomIds)) {
            String[] split = roomIds.split(",");
            for (String s : split) {
                try {
                    roomIdsList.add(Integer.valueOf(s));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return roomIdsList;
    }

    @ApiModelProperty("图片")
    public List<String> getImages() {
        try {
            return JSONUtil.parseObj(getExtraInfo()).getJSONArray("imgUrlList").toList(String.class);
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }

    @ApiModelProperty("星级")
    public String getStar() {
        Integer starLevel = getStarLevel();
        if (Objects.isNull(starLevel)) {
            return "";
        }
        switch (starLevel) {
            case 2:
                return "民宿";
            case 3:
            case 4:
            case 5:
                return "星级";
            case 6:
                return "商务";
            default:
                return "";
        }
    }

    @ApiModelProperty("最低价")
    public Integer getMinPrice() {
        if (CollectionUtil.isNotEmpty(this.rooms)) {
            try {
                Integer minPrice = this.rooms.get(0).getReferencePrice();
                for (HotelInfoHotelUnionSearchVoRoom room : this.rooms) {
                    if (minPrice > room.getReferencePrice()) {
                        minPrice = room.getReferencePrice();
                    }
                }
                return minPrice;
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return 999999;
    }

    @ApiModelProperty("设施列表")
    public List<String> getInstallation() {
        try {
            return CollectionUtil.newArrayList(JSONUtil.parseObj(getExtraInfo()).getStr("devices").split(","));
        } catch (Exception e) {
            return new ArrayList<>();
        }
    }


}
